package com.shun.oss.service;

import cn.hutool.core.date.DateUtil;
import com.shun.oss.common.FILE_TYPE;
import com.shun.oss.common.OSS_CTL_TYPE;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;

/**
 * 业务服务接口
 * @author clever
 * @since 2021-10-16
 */
@Slf4j
@Service
public class OssBizService {

    @Autowired
    private OssExecuteService executeService;

    /**
     * 上传私有化文件
     * @param fileName
     * @param stream
     * @return
     */
    public boolean addNMediaImgFile(String fileName, InputStream stream){
        log.debug("上传文件，fileName:{}",fileName);
        String path = FILE_TYPE.MEDIA.type+"/img/"+ DateUtil.format(DateUtil.date(),"yyyyMMdd")+"/"+fileName;
        return executeService.uploadFile(path,stream, OSS_CTL_TYPE.CTL_PRIVATE);
    }

    /**
     * 上传公共化文件
     * @param fileName
     * @param stream
     * @return
     */
    public boolean addYMediaImgFile(String fileName, InputStream stream){
        log.debug("上传文件，fileName:{}",fileName);
        String path = FILE_TYPE.MEDIA.type+"/img/"+ DateUtil.format(DateUtil.date(),"yyyyMMdd")+"/"+fileName;
        return executeService.uploadFile(path,stream, OSS_CTL_TYPE.CTL_PUBLIC_READ);
    }

    /**
     * 系统为公共化文件
     * @param fileName
     * @param stream
     * @return
     */
    public boolean addSysImgFile(String fileName, InputStream stream){
        log.debug("上传文件，fileName:{}",fileName);
        String path = FILE_TYPE.SYSTEM.type+"/img/"+ DateUtil.format(DateUtil.date(),"yyyyMMdd")+"/"+fileName;
        return executeService.uploadFile(path,stream, OSS_CTL_TYPE.CTL_PUBLIC_READ);
    }
}
